﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace IT_Pro.Class
{
    class CV_BanGiaoThietBi
    {
        private string _maMay;

        public string MaMay
        {
            get { return _maMay; }
            set { _maMay = value; }
        }
        private DateTime _ngayGiao;

        public DateTime NgayGiao
        {
            get { return _ngayGiao; }
            set { _ngayGiao = value; }
        }
        private string _maNguoiGiao;

        public string MaNguoiGiao
        {
            get { return _maNguoiGiao; }
            set { _maNguoiGiao = value; }
        }
        private string _maNguoiNhan;

        public string MaNguoiNhan
        {
            get { return _maNguoiNhan; }
            set { _maNguoiNhan = value; }
        }
        private string _tinhTrang;

        public string TinhTrang
        {
            get { return _tinhTrang; }
            set { _tinhTrang = value; }
        }
        private string _ghiChu;

        public string GhiChu
        {
            get { return _ghiChu; }
            set { _ghiChu = value; }
        }

        public static bool ThucHienBanGiao(CV_BanGiaoThietBi bg)
        {
            string strSQL = "Select * from CV_BanGiaoThietBi where MaMay='"+bg.MaMay+"' and NguoiNhan='"+bg.MaNguoiGiao+"'";
            DataTable dt = DataServices.ExecQuery(strSQL);
            if (dt.Rows.Count > 0)
            {
                strSQL = "update CV_BanGiaoThietBi SET Giu='0' where MaMay='" + bg.MaMay + "' and NguoiNhan='" + bg.MaNguoiGiao + "'";
                DataServices.ExecNonQuery(strSQL);
            }            
                strSQL = "insert into CV_BanGiaoThietBi(MaMay,NgayGiao,NguoiGiao,NguoiNhan,TinhTrang,Giu,GhiChu) values ('" + bg.MaMay + "','" + bg.NgayGiao + "','" + bg.MaNguoiGiao + "','" + bg.MaNguoiNhan + "',N'" + bg.TinhTrang + "','1',N'"+bg.GhiChu+"')";
                DataServices.ExecNonQuery(strSQL);
                return true;           
        }

        public static bool KiemTraNhanVienCoGiuMay(string _manv)
        {
            string strSQL = "select * from CV_BanGiaoThietBi where NguoiNhan='"+_manv+"' and Giu='1'";
            DataTable dt= DataServices.ExecQuery(strSQL);
            if (dt.Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static DataTable HienThiDanhSachBanGiao(string _manv)
        {
            string strSQL = "select 0 as STT,* from CV_BanGiaoThietBi bg,NV_NhanVien nv where bg.NguoiGiao=nv.MaNV and bg.NguoiNhan='" + _manv + "' and Giu='1'";
           return  DataServices.ExecQuery(strSQL);
        }

        public static DataTable LayDSVuaBanGiao(string nguoinhan,string mamay)
        {
            string strSQL = "select * from CV_BanGiaoThietBi bg,MT_ChiTietMayTinh ctmt,MT_DanhMucLinhKien dm where ctmt.LinhKien=dm.MaLK and bg.MaMay=ctmt.MaMay and bg.Giu=1 and bg.NguoiNhan='" + nguoinhan + "' and bg.MaMay='" + mamay + "'";
            return DataServices.ExecQuery(strSQL);
        }
    }
}
